package com.dxb.uc.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("dynamic")
@RefreshScope
public class DynamicController {

    @Value("${nacos.share}")
    private String share;
    @Value("${nacos.local}")
    private String local;
    @Value("${nacos.nacos}")
    private String nacos;

    @Value("${share.config1}")
    private String shareConfig1;

    @Value("${share.config2}")
    private String shareConfig2;

    @Value("${share.config3}")
    private String shareConfig3;

    @Value("${share.config4}")
    private String shareConfig4;

    @GetMapping("config")
    public Object config() {
        Map<String, String> map = new HashMap<>();
        //本地和远程合并，远程覆盖本地
        map.put("nacos.share", share);
        map.put("nacos.local", local);
        map.put("nacos.nacos", nacos);
        //本组共享
        map.put("share.config1", shareConfig1);
        map.put("share.config2", shareConfig2);
        //不同组共享，覆盖本组共享
        map.put("share.config3", shareConfig3);
        map.put("share.config4", shareConfig4);
        return map;
    }
}
